import java.util.Objects;

/**
 * @Author YuanYuan
 * @Date 2022/9/13
 * @Time 20:38
 */
public class TestDemo2 {
    public static void main2(String[] args) {
        Object object1 = new Object();
        Thread thread = new Thread(() -> {
            synchronized (object1) {
                System.out.println("开始等待:");
                try {
                    object1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("等待结束!");
            }
        });
        thread.start();
    }
    public static void main(String[] args) {
        Object object = new Object();
        Thread thread = new Thread(()-> {
            synchronized (object) {
                System.out.println("wait之前");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("wait 之后");
            }
        });

        Thread thread1 = new Thread(()-> {
            synchronized (object) {
                System.out.println("notify 之前");
                object.notify();
                System.out.println("notify 之后");
            }
        });

        thread.start();
        thread1.start();

    }
}
